
#if NO_CMDLINE
#else

#include "Shell.h"
#include "debug.h"
#include "CmdParser.h"
#include "Mmc.h"
#include "driver_max6692.h"
#include "driver_adc.h"
#include "Driver_ek.h"
#include "FruInfoTester.h"
#include "MMC_Appi.h"
#include "ConfigInfoTester.h"

CmdParser g_CmdParser;

#if 0
void Cmd_Test0()
{
	SHELL(("%s()\n",_FUNC_));
}
void Cmd_Test1(uint32 value)
{
	SHELL(("%s(%d)\n",_FUNC_, value));
}
uint32 Cmd_Test2(uint32 value, uint32 value1)
{
	SHELL(("%s(%d, %d)\n",_FUNC_, value, value1));
	return 1;
}
#endif
static uint32 g_dwTemp = 0;
#define BUFF_SIZE  255
static uint8	g_Buff[BUFF_SIZE];

void Set_Led_State(void* pLed, uint8 color, Bool isOn)
{
}

static int Cmd_CrbDone(Sensor* pSensor, Crb* pCrb, uint8 State)
{
	TRACE_LEVEL(TRACE_SHELL, ("%s, state=%d\n", _FUNC_, State));
	if(CRB_RX_RSP_SUCCESS == State)
	{
		TRACE_LEVEL(TRACE_SHELL, ("%s, Dump Rsp[%d]:", pCrb->m_pRspIpmiCmd->m_CmdLen));
		DUMP_BYTE(pCrb->m_pRspIpmiCmd->m_pCmdData, pCrb->m_pRspIpmiCmd->m_CmdLen);
	}

	g_dwDebugLevel = g_dwTemp;
	return ERR_SUCCESS;
}

int Cmd_GetDeviceId(CmdParser* pCmdParser)
{
	Crb* pCrb = (Crb*)&g_Mmc.m_ReqCrb;
	static ReqData req =
	{
		GET_DEVICE_ID, NETFUN_APPLICA_REQ, CMD_EVENT_LUN, 0, (CrbNotifyFun)Cmd_CrbDone, Null, 0
	};
	
	req.m_pRequester = Null;
	g_dwTemp = g_dwDebugLevel;
	g_dwDebugLevel |= TRACE_IPMB;
	
	return Crb_SendReq(pCrb, &req);
}

int Cmd_DumpSensor(CmdParser* pCmdParser)
{
	int i = 0;

	for(i = 0; i < MAX_SENSOR_COUNT; i++)
	{
		if(g_Mmc.m_pSensor[i])
		{
			SHELL(("SensorId=%s, \tSensorName=%d\n", g_Mmc.m_pSensor[i]->m_SensorId, g_Mmc.m_pSensor[i]->m_IdString));
		}
	}

	return 0;
}

//Cmd_GetSensorState(uint8 sensorId)
int Cmd_GetSensorState(CmdParser* pCmdParser)
{
	//Sensor Test
	{
		uint8 temp[4]={0};
		
		SHELL(("Sensor Hot swap = %s\n", Is_HandSwitch_Close() ? "Closed" : "Opened"));

		if(ERR_SUCCESS != Send_OneShot())
		{
			SHELL(("Sensor Temp Send_OneShot Failed!\n"));
		}
		if(ERR_SUCCESS == Read_Max6692Temperature(temp))
		{
			SHELL(("Sensor Temp=[%d.%d][%d.%d]\n", temp[0], temp[1], temp[2], temp[3]));
		}
		else
		{
			SHELL(("Sensor Temp read error!\n"));
		}
	}

	{
		uint32 V33=ADC_Convert(1);
	    uint32 V12=ADC_Convert(3);
		SHELL(("Sensor 3.3V=%d[%d]\nSensor 12V =%d[%d]\n", (V33 * 33 * 200) / 102400, V33, (V12 * 33 * 502) / 102400, V12));
		
	}
	
	return 0;
}

//Cmd_FruDevTest(uint8 op/*1-Write,2-Read,3-W/R*/, uint16 offset, uint8 len)
int Cmd_FruDevTest(CmdParser* pCmdParser)	
{
	uint8 op = (uint8)pCmdParser->m_Args[0];
	uint16 offset = pCmdParser->m_Args[1];
	uint8 len = (uint8)pCmdParser->m_Args[2];
	int i = 0;
	Bool bFlag = True;

	for(i = 0; i < BUFF_SIZE; i++)
	{
		g_Buff[i] = i;
	}
	
	if(pCmdParser->m_ArgsCount != 3)
	{
		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}

	if(op & 1)
	{
		bFlag = Mmc_WriteFruDevice(Null, offset, g_Buff, len);
		SHELL(("Write Fru Device[%d,%d] %s, Len=%d\n", offset, len, bFlag ? "Success" : "Failed"));
		SHELL(("Dump write data:\n"));
		DUMP_BYTE(g_Buff, len);
	}
	
	if(op & 2)
	{
		bFlag = Mmc_ReadFruDevice(Null, offset, g_Buff, len);
		SHELL(("Read Fru Device[%d,%d] %s, Len=%d\n", offset, len, bFlag ? "Success" : "Failed"));
		SHELL(("Dump read data:\n"));
		DUMP_BYTE(g_Buff, len);;
	}

	if(op & 3)
	{
		for(i = 0; i < len; i++)
		{
			if(g_Buff[i] != i)
			{
				SHELL(("Verify data[%d] failed!\n", i));
				break;
			}
		}
	}
	return False;
}

void Shell_SetFru(Bool isSetDefault)
{
	Bool bFlag = True;
	FruInfo* pFruInfo = &g_Mmc.m_ConfigInfo;
	
	FruInfo_Reset(pFruInfo);
	if(!isSetDefault)
	{
		memset(pFruInfo->m_Buffer, 0, pFruInfo->m_FruAreaSize);
	}
	else
	{
		MmcFruInfo_SetDefault(pFruInfo);
	}

	//DUMP_BYTE(pFruInfo->m_Buffer, pFruInfo->m_UsedBufLen);

	bFlag = FruInfo_Write(pFruInfo);
	SHELL(("Write Fru Device %s, Len=%d\n", bFlag ? "Success" : "Failed", pFruInfo->m_UsedBufLen));
	if(!bFlag) return;

	bFlag = FruInfo_Read(pFruInfo);
	SHELL(("Read Fru Device %s, Len=%d\n", bFlag ? "Success" : "Failed", pFruInfo->m_UsedBufLen));
	if(!bFlag) return;

	bFlag = FruInfo_Parse(pFruInfo);
}

void Shell_SetConfig(Bool isSetDefault)
{
	Bool bFlag = True;
	FruInfo* pFruInfo = &g_Mmc.m_ConfigInfo;
	
	FruInfo_Reset(pFruInfo);
	if(!isSetDefault)
	{
		memset(pFruInfo->m_Buffer, 0, pFruInfo->m_FruAreaSize);
	}
	else
	{
		CfgTester_SetDefault(pFruInfo, g_Owerner_IPMB_Addr, g_Owerner_Sit_Num);
	}

	//DUMP_BYTE(pFruInfo->m_Buffer, pFruInfo->m_UsedBufLen);

	bFlag = FruInfo_Write(pFruInfo);
	SHELL(("Write Fru Device %s, Len=%d\n", bFlag ? "Success" : "Failed", pFruInfo->m_UsedBufLen));
	if(!bFlag) return;

	bFlag = FruInfo_Read(pFruInfo);
	SHELL(("Read Fru Device %s, Len=%d\n", bFlag ? "Success" : "Failed", pFruInfo->m_UsedBufLen));
	if(!bFlag) return;

	bFlag = FruInfo_Parse(pFruInfo);
}

int Cmd_SetFru(CmdParser* pCmdParser)	//Cmd_SetFru(Bool isSetDefault)
{
	if(pCmdParser->m_ArgsCount != 1)
	{
		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}
	
	g_dwTemp = g_dwDebugLevel;
	g_dwDebugLevel |= TRACE_FRU;
	
	Shell_SetFru(pCmdParser->m_Args[0]);

	g_dwDebugLevel = g_dwTemp;
	return 0;
}

int Cmd_SetConfig(CmdParser* pCmdParser)	//Cmd_SetConfig(Bool isSetDefault)
{
	if(pCmdParser->m_ArgsCount != 1)
	{
		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}
	
	g_dwTemp = g_dwDebugLevel;
	g_dwDebugLevel |= TRACE_FRU;
	
	Shell_SetConfig(pCmdParser->m_Args[0]);

	g_dwDebugLevel = g_dwTemp;
	return 0;
}


int Cmd_WdEnable(CmdParser* pCmdParser)	//(uint8 isEnable)
{
	if(pCmdParser->m_ArgsCount != 3)
	{
		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}
	SHELL(("Feed watch dog %s\n", pCmdParser->m_Args[0] ? "Enable" : "Disable"));

	gWatchDogSwitch = pCmdParser->m_Args[0];

	return 0;
}

#ifndef WIN32
int Cmd_SelfTest(CmdParser* pCmdParser)
{
	#define UART_SCAN(string, input)	\
			SHELL(("%s", string));	\
			do	\
			{	\
				if(Uart_Scan(0, &input, 1))	\
				{	\
					SHELL((">%c\n", input));	\
					if(input != 'Y' && input != 'N' && input != 'n' && input != 'y')	\
					{	\
						SHELL(("Input error, Please input 'Y' or 'N'\n"));	\
					}	\
					else	\
					{	\
						break;	\
					}	\
				}	\
			}while(1)
	Bool testFailedCount = 0;
	uint8 input = 0;
	
	SHELL(("\n==========================================\n"));
	SHELL(("Self test start\n"));
	SHELL(("Fru device test=========================\n"));
	
	//Fru Device test
	Shell_SetConfig(True);
	if(g_Mmc.m_ConfigInfo.m_State != FRU_VERIFY_SUCCESS)
	{
		testFailedCount++;
	}
	
	Shell_SetFru(True);
	if(g_Mmc.m_FruInfo.m_State != FRU_VERIFY_SUCCESS)
	{
		testFailedCount++;
	}
	
	//Fru Device test
	g_Mmc.m_BlueLed.SetLed = (SetLedFun)Set_Led_State;
	g_Mmc.m_Led1.SetLed = (SetLedFun)Set_Led_State;
	
	Set_LedAlarm_State(True);
	UART_SCAN("Led1 is ON? (Y/N)\n", input);
	if(input == 'Y' || input == 'y')
	{
		SHELL(("Led1 ON test passed.\n"));
	}
	else
	{
		SHELL(("Led1 ON test failed.\n"));
		testFailedCount++;
	}
	
	Set_LedAlarm_State(False);
	UART_SCAN("Led1 is OFF? (Y/N)\n", input);
	if(input == 'Y' || input == 'y')
	{
		SHELL(("Led1 OFF test passed.\n"));
	}
	else
	{
		SHELL(("Led1 OFF test failed.\n"));
		testFailedCount++;
	}
	
	Set_LedBlue_State(True);
	UART_SCAN("BlueLed is ON? (Y/N)\n", input);
	if(input == 'Y' || input == 'y')
	{
		SHELL(("BlueLed ON test passed.\n"));
	}
	else
	{
		SHELL(("BlueLed ON test failed.\n"));
		testFailedCount++;
	}
	
	Set_LedBlue_State(False);
	UART_SCAN("BlueLed is OFF? (Y/N)\n", input);
	if(input == 'Y' || input == 'y')
	{
		SHELL(("BlueLed OFF test passed.\n"));
	}
	else
	{
		SHELL(("BlueLed OFF test failed.\n"));
		testFailedCount++;
	}

	//Handle sensor test
	SHELL(("handle switch Sensor test=========================\n"));
	UART_SCAN("Please to close handle switch. (Y)\n", input);
	if(input == 'Y' || input == 'y')
	{
		if(Is_HandSwitch_Close())
		{
			SHELL(("Handle switch is CLOSED, Test passed\n"));
		}
		else
		{
			SHELL(("Handle switch is OPENED, Test failed\n"));
			testFailedCount++;
		}
	}

	UART_SCAN("Please to open handle switch. (Y)\n", input);
	if(input == 'Y' || input == 'y')
	{
		if(Is_HandSwitch_Close())
		{
			SHELL(("Handle switch is CLOSED, Test failed\n"));
			testFailedCount++;
		}
		else
		{
			SHELL(("Handle switch is OPENED, Test passed\n"));
		}
	}
	
	//Sensor Test
	{
		uint8 temp[4]={0};
		
		SHELL(("Sensor test=========================\n"));
		
		
		if(ERR_SUCCESS == Read_Max6692Temperature(temp))
		{
			SHELL(("Sensor Temp=[0x%x][0x%x][0x%x][0x%x]\n", temp[0], temp[1], temp[2], temp[3]));
		}
		else
		{
			SHELL(("Sensor Temp read error!\n"));
		}
	}

	{
		uint32 V33=ADC_Convert(1);
	    uint32 V12=ADC_Convert(3);
		//SHELL(("3.3V Sensor=%d, 12V Sensor=%d\n", V33, V12));
		if(V33 >= 31 || V33 <= 35)
		{
			SHELL(("3.3V Sensor test passed, value=%d.\n", V33));
		}
		else
		{
			SHELL(("3.3V Sensor test failed, value=%d.\n", V33));
			testFailedCount++;
		}

		UART_SCAN("Is Payload power enable? (Y/N)\n", input);
		
		if(input == 'Y' || input == 'y')
		{
			if(V12 >= 119 || V12 <= 121)
			{
				SHELL(("12V Sensor test passed, value=%d.\n", V12));
			}
			else
			{
				SHELL(("12V Sensor test failed, value=%d.\n", V12));
				testFailedCount++;
			}
		}
		else
		{
			if(V12 <= 1)
			{
				SHELL(("12V Sensor test passed, value=%d.\n", V12));
			}
			else
			{
				SHELL(("12V Sensor test failed, value=%d.\n", V12));
				testFailedCount++;
			}
		}
		
	}
	
	/*/E-Keying test
	{
		Bool isOk = False;
		uint8 portState[4] = {0xF0, 0xFF, 0xF0, 0xFF};
		
		SHELL(("E-Keying test=========================\n"));
		
		DriverEk_SetState(PCF8574_1, portState[0]);
		DriverEk_SetState(PCF8574_2, portState[1]);
		DriverEk_SetState(PCF8574_3, portState[2]);
		DriverEk_SetState(PCF8574_4, portState[3]);

		if(DriverEk_GetState(PCF8574_1) != portState[0])
		{
			isOk = False;
		}
		
		if(DriverEk_GetState(PCF8574_2) != portState[1])
		{
			isOk = False;
		}
		
		if(DriverEk_GetState(PCF8574_3) != portState[2])
		{
			isOk = False;
		}
		
		if(DriverEk_GetState(PCF8574_3) != portState[3])
		{
			isOk = False;
		}

		if(!isOk)
		{
			SHELL(("E-Keying test %s\n", isOk ? "Success" : "Failed"));
		}
		else
		{
			testFailedCount++;
		}
	}
	*/

	SHELL(("==========================================\n"));
	SHELL(("Self test is completed, testFailedCount=%d.\n", testFailedCount));
	
	return 0;
}
#endif

int Cmd_GetPort(CmdParser* pCmdParser)	//(uint8 port)
{
	SHELL(("PCF8574[1]=[0x%02x][0x%02x][0x%02x][0x%02x]\n"
		, DriverEk_GetState(PCF8574_1)
		, DriverEk_GetState(PCF8574_2)
		, DriverEk_GetState(PCF8574_3)
		, DriverEk_GetState(PCF8574_4)
		));

	return 0;
}

int Cmd_SetPort(CmdParser* pCmdParser)	//(uint8 addr, uint8 value, uint8 mask)
{
	uint8 addr = (uint8)pCmdParser->m_Args[0];
	uint8 value =(uint8)pCmdParser->m_Args[1];
	uint8 mask = (uint8)pCmdParser->m_Args[2];
	if(pCmdParser->m_ArgsCount != 3)
	{
		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}
	if(addr != PCF8574_1 && addr != PCF8574_2 && addr != PCF8574_3 && addr != PCF8574_4)
	{
		SHELL(("\t Arguments addr[%d] error.\n", addr));
		return 0;
	}
	
	DriverEk_SetState(addr, value & mask);
	DriverEk_GetState(addr);
	
	return 0;
}

int Cmd_SetLed(CmdParser* pCmdParser)	//(uint8 ledId/*All led=0xFF,*/, uint8 mode/*off/on/shine=1/2/3*/, uint16 shineOff, uint16 ShineOn)
{
	Led* pLed = Null;
	uint8 ledId = (uint8)pCmdParser->m_Args[0];
	LedWorkMode mode = (LedWorkMode)pCmdParser->m_Args[1];
	uint16 shineOff = (uint16)pCmdParser->m_Args[2];
	uint16 ShineOn = (uint16)pCmdParser->m_Args[3];
	
	if(pCmdParser->m_ArgsCount != 4)
	{

		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}

	if(ledId == 0xFF)
	{
		Led_SetWorkMode(&g_Mmc.m_BlueLed, mode, shineOff, ShineOn, OVERRIDE_CONTROL);
		Led_SetWorkMode(&g_Mmc.m_Led1, mode, shineOff, ShineOn, OVERRIDE_CONTROL);
		return 0;
	}
	else
	{
		pLed = Mmc_GetLed(ledId);
	}
	if(pLed == Null)
	{
		SHELL(("\t ledId[0] error.\n"));
		return 0;
	}
	
	Led_SetWorkMode(pLed, mode, shineOff, ShineOn, OVERRIDE_CONTROL);
	return 0;
}

int Cmd_TimerDisable(CmdParser* pCmdParser)	//Cmd_TimerDisable(uint8 isDisable)
{
	if(pCmdParser->m_ArgsCount != 1)
	{
		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}

	g_Mmc.m_isTimerDisable = pCmdParser->m_Args[0];

	return 0;
}

int Cmd_ExcuteFun(CmdParser* pCmdParser)
{
	ShellFun0 p0 = (ShellFun0)pCmdParser->m_Args[0];
	ShellFun1 p1 = (ShellFun1)pCmdParser->m_Args[0];
	ShellFun2 p2 = (ShellFun2)pCmdParser->m_Args[0];
	ShellFun3 p3 = (ShellFun3)pCmdParser->m_Args[0];
//	ShellFun4 p4 = (ShellFun4)pCmdParser->m_Args[0];
	
	if(1 == pCmdParser->m_ArgsCount)
	{
		p0();
	}
	else if(2 == pCmdParser->m_ArgsCount)
	{
		p1(pCmdParser->m_Args[1]);
	}
	else if(3 == pCmdParser->m_ArgsCount)
	{
		p2(pCmdParser->m_Args[1], pCmdParser->m_Args[2]);
	}
	else if(4 == pCmdParser->m_ArgsCount)
	{
		p3(pCmdParser->m_Args[1], pCmdParser->m_Args[2], pCmdParser->m_Args[3]);
	}

	return 0;
}

int Cmd_SetVar(CmdParser* pCmdParser)	//SetVar(char* varName, uint32 value)
{
	Bool isFind = False;
	
	#define SET_VAR(varName) \
		if(strcmp((char*)pCmdParser->m_String, #varName) == 0)	\
		{	\
			isFind = True;	\
			varName = pCmdParser->m_Args[1];	\
			SHELL(("%s=%d\n", pCmdParser->m_String, pCmdParser->m_Args[1]));	\
		}
	
	if(pCmdParser->m_ArgsCount != 2)
	{
		SHELL(("Arguments count[%d] error. Dump var:\n", pCmdParser->m_ArgsCount));
		PRINT_VAR(gDelay);
		PRINT_VAR(g_dwDebugLevel);
		PRINT_VAR(g_Owerner_Sit_Num);
		PRINT_VAR(g_Owerner_SIT_TYPE);
		PRINT_VAR(g_Owerner_IPMB_Addr);
		PRINT_VAR(g_Owerner_IPMB_Type);
		return 0;
	}

	SET_VAR(gDelay);
	SET_VAR(g_dwDebugLevel);
	SET_VAR(g_Owerner_Sit_Num);
	SET_VAR(g_Owerner_SIT_TYPE);
	SET_VAR(g_Owerner_IPMB_Addr);
	SET_VAR(g_Owerner_IPMB_Type);

	if(!isFind)
	{
		SHELL(("No variable \"%s\".\n", (char*)pCmdParser->m_String));
	}
	return 0;
}

int Cmd_GetVar(CmdParser* pCmdParser)	//GetVar(char* varName)
{
	Bool isFind = False;
	
	#define GET_VAR(varName) \
		if(strcmp((char*)pCmdParser->m_String, #varName) == 0)	\
		{	\
			isFind = True;	\
			SHELL(("%s=%d\n", pCmdParser->m_String, varName));	\
		}
	
	if(pCmdParser->m_ArgsCount != 1)
	{
		PRINT_VAR(gDelay);
		PRINT_VAR(g_dwDebugLevel);
		return 0;
	}

	GET_VAR(gDelay);
	GET_VAR(g_dwDebugLevel);

	if(!isFind)
	{
		SHELL(("No variable \"%s\".\n", (char*)pCmdParser->m_String));
	}
	return 0;
}

int Cmd_Set(CmdParser* pCmdParser)	//Set(uint32* pPointer, uint32 value, uint32 mask)
{
	uint8 i = 0;
	uint32* pUint32 = 0;
	
	if(pCmdParser->m_ArgsCount != 3)
	{
		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}

	pUint32 = (uint32*)pCmdParser->m_Args[0];

	for(i = 0; i < 32; i++)
	{
		if((pCmdParser->m_Args[2] >> i) & 0x01)
		{
			if((pCmdParser->m_Args[1]) >> i & 0x01)
			{
				*pUint32 |= (1 << i);
			}
			else
			{
				*pUint32 &= ~(1 << i);
			}
		}
	}
	
	SHELL(("\t @0x%08x = [0x%08x][%d]\n", pCmdParser->m_Args[0], *pUint32, *pUint32));
	
	return 0;
}


uint8 GetBitOffset(uint32 value)
{
	uint8 i = 0;
	for(i = 0; i < 32; i++)
	{
		if(value == (1<<i))
		{
			return i;
		}
	}

	return 0;
}
#define PRINTF_DEBUG_BIT(x) SHELL(("\t [%d] = Bit[%02d]:%s\n", ((g_dwDebugLevel & x) ? 1 : 0), GetBitOffset(x), #x))
int Cmd_SetDebugBit(CmdParser* pCmdParser)
{
	int i = 0;

	if(pCmdParser->m_ArgsCount < 2)
	{
		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}
	
	if(pCmdParser->m_Args[pCmdParser->m_ArgsCount-1] == 0)
	{
		for(i = 0; i < pCmdParser->m_ArgsCount-1; i++)
		{
			g_dwDebugLevel &= ~(1 << pCmdParser->m_Args[i]);
		}
	}
	else if(pCmdParser->m_Args[pCmdParser->m_ArgsCount-1] == 1)
	{
		for(i = 0; i < pCmdParser->m_ArgsCount-1; i++)
		{
			g_dwDebugLevel |= (1 << pCmdParser->m_Args[i]);
		}
	}
	else
	{
		g_dwDebugLevel = pCmdParser->m_Args[0];
	}


	PRINTF_DEBUG_BIT(TRACE_MAIN 	);
	PRINTF_DEBUG_BIT(TRACE_WARNING	);
	PRINTF_DEBUG_BIT(TRACE_ASSERT	);
	PRINTF_DEBUG_BIT(TRACE_FRU 	);
	PRINTF_DEBUG_BIT(TRACE_CRB		);
	PRINTF_DEBUG_BIT(TRACE_TRANSFER);
	PRINTF_DEBUG_BIT(TRACE_SHELL	);
	PRINTF_DEBUG_BIT(TRACE_IPMB 	);
	PRINTF_DEBUG_BIT(TRACE_CMD_HANDLE);
	PRINTF_DEBUG_BIT(TRACE_IPMICMD 	);
	PRINTF_DEBUG_BIT(TRACE_IPMICMDDATA);
	PRINTF_DEBUG_BIT(TRACE_SENSOR 		);
	PRINTF_DEBUG_BIT(TRACE_MSG 		);
	PRINTF_DEBUG_BIT(TRACE_LIST		);
	PRINTF_DEBUG_BIT(TRACE_SDR			);
	PRINTF_DEBUG_BIT(TRACE_TIMER 		);
	
	SHELL(("\t g_dwDebugLevel[@0x%08x] = [0x%08x]\n", &g_dwDebugLevel, g_dwDebugLevel));
	return 0;
}

int Cmd_DataDump(CmdParser* pCmdParser)
{
	if(pCmdParser->m_ArgsCount != 3)
	{
		SHELL(("\t Arguments count[%d] error.\n", pCmdParser->m_ArgsCount));
		return 0;
	}
	
	if(0 == pCmdParser->m_Args[1])
	{
		pCmdParser->m_Args[2] = 32;
	}

	SHELL(("%s(0x%x, 0x%x, 0x%x)\n", _FUNC_, pCmdParser->m_Args[0], pCmdParser->m_Args[1], pCmdParser->m_Args[2]));
	
	Debug_DumpByte((uint8*)pCmdParser->m_Args[0], pCmdParser->m_Args[1], pCmdParser->m_Args[2]);

	return 0;
}


const static CmdLine g_CmdTable[] = 
{
	 {"?"				,Cmd_Help			, "Help"}
	,{"ExcuteFun"		,Cmd_ExcuteFun		, "ExcuteFun(uint32 funAddr, uint32 args1, uint32 args2, uint32 args3)"}
	,{"Set"				,Cmd_Set			, "Set(uint32* pPointer, uint32 value, uint32 mask)"}
	,{"SetVar"			,Cmd_SetVar			, "SetVar(char* string, uint32 value)"}
	,{"GetVar"			,Cmd_GetVar			, "GetVar(char* string)"}
	,{"SetDebugBit"		,Cmd_SetDebugBit	, "SetDebugBit(uint8 bit, uint8 isEnable)"}
	,{"DataDump"		,Cmd_DataDump		, "DataDump(uint32* pPointer, uint8 len, uint8 nCol)"}
	,{"SetLed"			,Cmd_SetLed			, "SetLed(uint8 ledId/*Blueled=0,led1=1,All led=0xFF*/, uint8 mode/*off/on/shine=1/2/3*/, uint16 shineOff, uint16 ShineOn)"}
#ifndef WIN32
	,{"SelfTest"		,Cmd_SelfTest		, "SelfTest()"}
#endif
	,{"SetFru"			,Cmd_SetFru			, "SetFru(Bool isSetDefault)"}
	,{"SetConfig"		,Cmd_SetConfig		, "SetConfig(Bool isSetDefault)"}
	,{"GetPort"			,Cmd_GetPort		, "GetPor()"}
	,{"SetPort"			,Cmd_SetPort		, "SetPort(uint8 addr/*0x42,0x44,0x46*/, uint8 value, uint8 mask)"}
	,{"WdEnable"		,Cmd_WdEnable		, "WdEnable(uint8 isEnable)"}
	,{"TimerDisable"	,Cmd_TimerDisable	, "TimerDisable(uint8 isDisable)"}
	,{"FruDevTest"		,Cmd_FruDevTest		, "FruDevTest(uint8 op/*1-Write,2-Read,3-W/R*/, uint16 offset, uint8 len)"}
	,{"DumpSensor"		,Cmd_DumpSensor		, "DumpSensor()"}
	,{"GetSensorState"	,Cmd_GetSensorState	, "GetSensorState()"}
	,{"GetDeviceId"		,Cmd_GetDeviceId	, "GetDeviceId()"}
};

int Cmd_Help(CmdParser* pCmdParser)
{
	int i = 0;
	
	for(i = 0; i < sizeof(g_CmdTable) / sizeof(CmdLine); i++)
	{
		const CmdLine* pCmdLine = &g_CmdTable[i];
		
		SHELL(("\t %s\n", pCmdLine->m_pHelp));
	}


	return 0;
}

void Shell_Init()
{
	TRACE_LEVEL(TRACE_MAIN,("Shell is supported\n"));
	CmdParser_Init(&g_CmdParser, g_CmdTable, sizeof(g_CmdTable)/sizeof(CmdLine), True);
}


#endif //#if NO_CMDLINE

